import { lazy } from 'react'
import {
  DashboardOutlined,
  UserOutlined,
  TeamOutlined,
  MenuOutlined,
  MonitorOutlined,
  FileTextOutlined,
  LineChartOutlined,
  FileOutlined,
  EditOutlined,
  TagsOutlined,
  BulbOutlined,
  SettingOutlined,
  RobotOutlined
} from '@ant-design/icons'
import { RouteConfig } from './types'

// 懒加载组件
const Login = lazy(() => import('@/pages/Login'))
const Dashboard = lazy(() => import('@/pages/Dashboard'))
const UserManagement = lazy(() => import('@/pages/UserManagement'))
const Roles = lazy(() => import('@/pages/System/Roles'))
const Menus = lazy(() => import('@/pages/System/Menus'))
const Logs = lazy(() => import('@/pages/Monitor/Logs'))
const Performance = lazy(() => import('@/pages/Monitor/Performance'))
const ThemeDemo = lazy(() => import('@/pages/ThemeDemo'))
const AIChat = lazy(() => import('@/pages/AIChat'))
const NotFound = lazy(() => import('@/components/NotFound'))

// 公共路由（不需要认证）
export const publicRoutes: RouteConfig[] = [
  {
    path: '/login',
    component: Login,
    name: '登录',
    showInMenu: false,
    requireAuth: false,
  },
  // 公共404路由 - 未登录时访问无效路径
  {
    path: '/404',
    component: NotFound,
    name: '404',
    showInMenu: false,
    requireAuth: false,
    meta: {
      is404: true,
      closable: true
    }
  }
]

// 私有路由（需要认证）
export const privateRoutes: RouteConfig[] = [
  {
    path: '/dashboard',
    component: Dashboard,
    name: '仪表盘',
    icon: DashboardOutlined,
    showInMenu: true,
    requireAuth: true,
    meta: {
      closable: false
    }
  },
  {
    path: '/system',
    name: '系统管理',
    icon: SettingOutlined,
    showInMenu: true,
    requireAuth: true,
    children: [
      {
        path: '/system/users',
        component: UserManagement,
        name: '用户管理',
        icon: UserOutlined,
        showInMenu: true,
        requireAuth: true,
      },
      {
        path: '/system/roles',
        component: Roles,
        name: '角色管理',
        icon: TeamOutlined,
        showInMenu: true,
        requireAuth: true,
      },
      {
        path: '/system/menus',
        component: Menus,
        name: '菜单管理',
        icon: MenuOutlined,
        showInMenu: true,
        requireAuth: true,
      }
    ]
  },
  {
    path: '/monitor',
    name: '系统监控',
    icon: MonitorOutlined,
    showInMenu: true,
    requireAuth: true,
    children: [
      {
        path: '/monitor/logs',
        component: Logs,
        name: '操作日志',
        icon: FileTextOutlined,
        showInMenu: true, // 显示已实现的菜单项
        requireAuth: true,
      },
      {
        path: '/monitor/performance',
        component: Performance,
        name: '性能监控',
        icon: LineChartOutlined,
        showInMenu: true, // 显示已实现的菜单项
        requireAuth: true,
      }
    ]
  },
  {
    path: '/content',
    name: '内容管理',
    icon: FileOutlined,
    showInMenu: true,
    requireAuth: true,
    children: [
      {
        path: '/content/articles',
        component: NotFound,
        name: '文章管理',
        icon: EditOutlined,
        showInMenu: false, // 隐藏未实现的菜单项
        requireAuth: true,
      },
      {
        path: '/content/categories',
        component: NotFound,
        name: '分类管理',
        icon: TagsOutlined,
        showInMenu: false, // 隐藏未实现的菜单项
        requireAuth: true,
      }
    ]
  },
  {
    path: '/ai-chat',
    component: AIChat,
    name: 'AI 助手',
    icon: RobotOutlined,
    showInMenu: true,
    requireAuth: true,
  },
  {
    path: '/theme-demo',
    component: ThemeDemo,
    name: '主题演示',
    icon: BulbOutlined,
    showInMenu: true,
    requireAuth: true,
  },
  // 404路由 - 必须放在最后，匹配所有未找到的路径
  {
    path: '*',
    component: NotFound,
    name: '页面未找到',
    showInMenu: false,
    requireAuth: true,
    meta: {
      is404: true,
      closable: true
    }
  }
]

/**
 * 所有路由配置
 */
export const allRoutes: RouteConfig[] = [
  ...publicRoutes,
  ...privateRoutes
]